/**
 *@author CEZERYE
 *@since 03.10.2011
 */
package model;

import java.util.ArrayList;
import checking.IdGenerator;
/**
 *in this class project manager do the applications about the project like add project.
 *
 */
public class HumanResources {

	
	private ArrayList<Project> projectList = new ArrayList<Project>();
	IdGenerator oId = new IdGenerator();
	

	//setter and getter methods
	public void setProjectList(ArrayList<Project> projectList) {
		this.projectList = projectList;
	}

	public ArrayList<Project> getProjectList() {
		return projectList;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		HumanResources other = (HumanResources) obj;
		if (oId == null) {
			if (other.oId != null)
				return false;
		} else if (!oId.equals(other.oId))
			return false;
		if (projectList == null) {
			if (other.projectList != null)
				return false;
		} else if (!projectList.equals(other.projectList))
			return false;
		return true;
	}

	/**
	 * @param oProject
	 * @return oProject
	 */
	public Project addProject(String name, String desc, String startDate, int pManagerId)
	{
		Project oProject = new Project(oId.generateId(),name, desc,startDate,pManagerId);
		projectList.add(oProject);
		return oProject;
	}
	
	/**
	 * @param oProject
	 */
	
	//project id enter and delete the project
	public void removeProject(int pNumber)
	{
		for (int i=0; i< projectList.size();i++){
			if (projectList.get(i).getNumber().equals(pNumber)){
				for (int j=0; j<projectList.get(i).getActivityList().size();j++){
					projectList.get(i).getActivityList().remove(j);
				}
				projectList.remove(i);
				}
		}
	}
	/**
	 * this method is used to update the project
	 * @param id            id for the project will be updated
	 * @param name          name for the project will be updated
	 * @param desc          desc for the project will be updated
	 * @param startDate     startDate for the project will be updated
	 * @param activity      activity for the project will be updated
	 * @return updatedProject   the project which is updated
	 */
	public Project updateProject(int id,String name,String desc,String startDate)
	{
		Project updatedProject=null;
	    
		updatedProject=findProject(id);
		updatedProject.setName(name);
		updatedProject.setDesc(desc);
		updatedProject.setStartDate(startDate);
		  
		return updatedProject;
	}
	/**
	 * this method is used to find the project according to the id number which is int
	 * @param id
	 * @return foundProject
	 */
	public Project findProject(int id)
	{
		Project foundProject=null;
		
		for(int i=0;i<projectList.size();i++){		
		if(projectList.get(i).getNumber() == id){
			foundProject = projectList.get(i);
											}
		}
		
		return foundProject;
	}
	
	public void displayProjects(){
		System.out.println("Your project list is;\n");
		for(int i=0; i<projectList.size();i++){
			System.out.println(projectList.get(i).toString()+"\n");
		}

	}


}
